package com.homegoods.classify.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.homegoods.classify.R;
import com.homegoods.classify.model.BrandModel;
import com.homegoods.resource.SpacesItemDecoration;

import java.util.List;

/**
 * add shibo.zheng
 * 19/06/21
 * 品牌界面的adapter 其中包含品牌标题和品牌logo展示
 * （临时adapter使用方案）
 */

public class ZPBrandAdapter extends RecyclerView.Adapter<ZPBrandAdapter.BrandViewholder> {
    private Context mContext;
    private List<BrandModel> brandModels;

    public ZPBrandAdapter(Context mContext, List<BrandModel> brandModels) {
        this.mContext = mContext;
        this.brandModels = brandModels;
    }

    @NonNull
    @Override
    public BrandViewholder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.classify_brand_parent_item, viewGroup, false);
        BrandViewholder viewholder = new BrandViewholder(view);
        return viewholder;
    }

    @Override
    public void onBindViewHolder(@NonNull BrandViewholder holder, int i) {
        holder.brandText.setText(brandModels.get(i).getBrandTitle());
        holder.brandParentList.setLayoutManager(new GridLayoutManager(mContext, 3));
//        ZPOtherAdapter adapter = new ZPOtherAdapter(mContext, brandModels.get(i).getRightModels(), true);
        ZPBrandItemAdapter adapter = new ZPBrandItemAdapter(mContext, brandModels.get(i).getRightModels());
        holder.brandParentList.setAdapter(adapter);
        holder.brandParentList.addItemDecoration(new SpacesItemDecoration(2, 2));
    }

    @Override
    public int getItemCount() {
        return brandModels.size();
    }

    public class BrandViewholder extends RecyclerView.ViewHolder {
        private TextView brandText;
        private RecyclerView brandParentList;

        public BrandViewholder(View itemView) {
            super(itemView);
            brandText = itemView.findViewById(R.id.brand_text);
            brandParentList = itemView.findViewById(R.id.brand_list);
        }
    }
}
